package executors.completable.future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class SupplyAsyncTest001 {
  public static void main(String[] args) throws ExecutionException, InterruptedException {
    CompletableFuture<String> supplyAsync = CompletableFuture.supplyAsync(() -> {
      System.out.println("这是提供一个生产者");
      try {
        TimeUnit.SECONDS.sleep(1);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
      System.out.println(Thread.currentThread().getName());
      return "a";
    });
    
    // get方法 有阻塞的功能
    System.out.println(supplyAsync.get());
    
    new Thread(() -> {
      System.out.println("这是一个单独的线程");
    }).start();
  }
}
